package com.huanletao.guava.it;

import com.google.common.base.CharMatcher;

public class CharMatcherDemo {
    public static void main(String[] args) {

        //只保留一个空白间隔
        String tmpStr = "  1   2   3 4 6    9   " ;
        String result = CharMatcher.whitespace().collapseFrom(tmpStr,'-');
        System.out.println(result);
//        -1-2-3-4-6-9-

        //删除开头和结尾的空白
        tmpStr = "  1   2   3 4 6    9   " ;
        result = CharMatcher.any().whitespace().trimAndCollapseFrom(tmpStr,'@');
        System.out.println( result);
//        1@2@3@4@6@9

        //获取0-6范围内的数字字符
        tmpStr = "df67sn18kj9" ;
        result = CharMatcher.inRange('0','9').retainFrom(tmpStr) ;
        System.out.println( result);
//        61

        //获取d-k范围内的数字字符
        tmpStr = "df67sn18kj9" ;
        result = CharMatcher.inRange('d','k').retainFrom(tmpStr) ;

        int i = CharMatcher.is('d').countIn(tmpStr);
        System.out.println("i = " + i);
        System.out.println( result);
//        dfkj

    }
}
